/*
 *  Copyright 2004 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.blandware.atleap.webapp.servlet;

import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import java.io.IOException;

/**
 * <p>DefaultServlet to process static resources. ONLY FOR TOMCAT!!!</p>
 * <p>This class is needed to allow filters to wrap requests for static resources in Tomcat</p>
 * <p/>
 * <p><a href="DefaultServlet.java.html"><i>View Source</i></a></p>
 *
 * @author Andrey Grebnev <a href="mailto:andrey.grebnev@blandware.com">&lt;andrey.grebnev@blandware.com&gt;</a>
 * @version $Revision: 1.2 $ $Date: 2005/08/04 17:25:19 $
 */
public class DefaultServlet extends HttpServlet {

    /**
     * The name of servlet which processes static resources in tomcat
     */
    protected static String DISPATCHER_NAME = "default";

    protected ServletConfig config = null;

    /**
     * Initializes the servlet.
     */
    public void init(ServletConfig config) throws ServletException {
        this.config = config;
        super.init(config);
    }

    /**
     * Destroys the servlet.
     */
    public void destroy() {
        config = null;
        super.destroy();
    }

    /**
     * Dispatches client requests to the protected
     * <code>service</code> method. There's no need to
     * override this method.
     *
     * @param req the {@link javax.servlet.http.HttpServletRequest} object that
     *            contains the request the client made of
     *            the servlet
     * @param res the {@link javax.servlet.http.HttpServletResponse} object that
     *            contains the response the servlet returns
     *            to the client
     * @throws java.io.IOException            if an input or output error occurs
     *                                        while the servlet is handling the
     *                                        HTTP request
     * @throws javax.servlet.ServletException if the HTTP request cannot
     *                                        be handled
     * @see javax.servlet.Servlet#service
     */

    public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
        RequestDispatcher requestDispatcher = config.getServletContext().getNamedDispatcher(DISPATCHER_NAME);
        requestDispatcher.forward(req, res);
    }
}